<?php
namespace App\Query;

use App\Model\UserLog;
use App\Query\Traits\UserTrait;

class UserLogQuery extends \HyperfStore\Query
{
    use UserTrait;
    
    // 构建模型
    protected static function build()
    {
        return UserLog::latest();
    }

    // 渴望加载
    protected static function with()
    {
        return ['user'];
    }
    
    // 时间区间
    protected static function queryTime($model, $where)
    {
        return $model->whereBetween('created_at', $where);
    }
    
    // 类型
    public static function type($type, $model = null)
    {
        return static::model($model)->where('type', $type);
    }
    
    // 类型
    public static function moneyType($type, $model = null)
    {
        return static::model($model)->where('money_type', $type);
    }
    
    // 获取今日
    public static function day($model = null)
    {
        return static::model($model)->where('created_at', '>=', strtotime(date('Y-m-d')));
    }
}